package cn.edu.zxj.springblog.mapper;

import cn.edu.zxj.springblog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description：针对Blog相关的数据库操作
 *
 * @author: zxj
 * @date: 2024-02-04
 * @time: 18:15:52
 */
@Mapper
public interface BlogInfoMapper {

    /**
     * @description: 获取所有博客列表
     **/
    @Select("select id, title, content,user_id,delete_flag,create_time,update_time " +
            "from blog where delete_flag = 0 order by id desc ")
    List<BlogInfo> selectAll();


    /**
     * @description: 根据博客ID查询博客信息
     **/
    @Select("select id, title, content,user_id,delete_flag,create_time,update_time " +
            "from blog where delete_flag = 0 and id = #{id}")
    BlogInfo selectById(Integer id);


    /**
     * @description: 删除博客, 修改 delete_flag 字段为1
     **/
    @Update("update blog set delete_flag = 1 where id = #{id}")
    Integer delete(Integer id);

    /**
     * @description: 编辑博客
     **/
    Integer update(BlogInfo blogInfo);


    /**
     * @description: 插入新的博客
     **/
    @Insert("insert into blog (title, content, user_id) values (#{title},#{content},#{userId})")
    Integer insert(BlogInfo blogInfo);
}
